package com.google.coffeeshop.dao.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.google.coffeeshop.dao.InvoiceDAO;
import com.google.coffeeshop.entity.EmployeeDTO;
import com.google.coffeeshop.entity.InvoiceDTO;
import com.googlecode.genericdao.search.Search;

public class InvoiceDAOImpl extends AbstractBaseDAOImpl<InvoiceDTO, Long> implements InvoiceDAO {

	public List<InvoiceDTO> findBetweenDates(Date beginDate, Date endDate, int status, EmployeeDTO employee){
		Search search = new Search(InvoiceDTO.class);
		search.setFirstResult(0);
		search.setMaxResults(Integer.MAX_VALUE);
		search.addFilterGreaterOrEqual("createDate", beginDate);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(endDate);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		search.addFilterLessOrEqual("createDate", calendar.getTime());
		search.addFilterEqual("status", status);
		if(employee != null)
			search.addFilterEqual("employee", employee);
		List<InvoiceDTO> invoices = this.search(search);
		if (null == invoices || invoices.isEmpty()) {
			return null;
		}
		return invoices;
	}
}
	
